package com.inossem.warehousestorage_inossem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.inossem.warehousestorage_inossem.R;

import java.util.List;

/**
 * Created by leij on 2017/6/6.
 */

public class OverviewAdapter extends BaseAdapter {

    private Context mContext;
    private List<OverviewBean> mOverviewList;
    private LayoutInflater inflater;

    public OverviewAdapter(Context context, List<OverviewBean> overviewList) {
        mContext = context;
        mOverviewList = overviewList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mOverviewList.size();
    }

    @Override
    public Object getItem(int position) {
        return mOverviewList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        OverviewBean overViewItem = mOverviewList.get(position);
        ViewHolder viewHolder;
        if (convertView == null || (convertView != null && convertView.getTag() == null)) {
            convertView = inflater.inflate(R.layout.dialog_overview, null);
            viewHolder = new ViewHolder();
            //初始化控件
            initView(viewHolder, convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //初始化数据
        initData(mContext, viewHolder, convertView, overViewItem);
        return convertView;
    }

    private void initView(ViewHolder viewHolder, View view) {
        viewHolder.info = (TextView) view.findViewById(R.id.info);
        viewHolder.number = (TextView) view.findViewById(R.id.number);
    }

    private void initData(Context context, ViewHolder viewHolder, View view, OverviewBean overViewItem) {
        viewHolder.info.setText(overViewItem.getInfo());
        viewHolder.number.setText(overViewItem.getNumber());
    }

    private class ViewHolder {
        private TextView info, number;
    }

    public static class OverviewBean{
        private String info;
        private String number;

        public String getInfo() {
            return info;
        }

        public void setInfo(String info) {
            this.info = info;
        }

        public String getNumber() {
            return number;
        }

        public void setNumber(String number) {
            this.number = number;
        }
    }
}
